<template>
  <el-card>
    <div slot="header" class="clearfix">
      <el-button type="primary" icon="el-icon-plus" class="mb-20"
        >添加</el-button
      >
    </div>
    <el-table border class="mb-10 mt-10" :data="pageInfo">
      <el-table-column
        label="序号"
        type="index"
        width="80"
        align="center"
      ></el-table-column>
      <el-table-column label="品牌名称" prop="tmName"></el-table-column>
      <el-table-column label="品牌LOGO">
        <template slot-scope="scope">
          <img :src="scope.row.logoUrl" style="width: 80px; height: 80px" />
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button icon="el-icon-edit-outline" type="warning">编辑</el-button>
          <el-button
            icon="el-icon-delete"
            type="danger"
            @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[3, 6, 9]"
      :page-size="limit"
      layout="prev, pager, next, jumper,->,sizes ,total"
      :total="total"
    >
    </el-pagination>
  </el-card>
</template>

<script>
import trademarkApi from "@/api/trademark";
export default {
  name: "Trademark",
  data() {
    return {
      pageInfo: [],
      page: 1,
      limit: 3,
      total: 40,
    };
  },
  methods: {
    // 每页多少条
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.limit = val;
      this.getPageInfo();
    },
    // 当前在哪页
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page = val;
      this.getPageInfo();
    },
    // 获取分页数据
    async getPageInfo() {
      const result = await trademarkApi.getPage(this.page, this.limit);
      // console.log(result);
      this.pageInfo = result.data.records;
      console.log(this.pageInfo);
      this.total = result.data.total;
    },
    // 删除按钮
    del(id) {
      this.$confirm("确认要删除该文件嘛?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          // 删除数据
          await trademarkApi.delete(id);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.getPageInfo();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 添加
  },
  mounted() {
    this.getPageInfo();
  },
};
</script>

<style lang="scss" scoped></style>
